<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

class ReturnPerformance extends Model
{
    use HasDateTimeFormatter, SoftDeletes;

    protected $guarded = [];


    //客户
    public function customer(): BelongsTo
    {
        return $this->belongsTo(Customer::class);
    }

    //复诊部
    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }


    public function doctor(): BelongsTo
    {
        return $this->belongsTo(Option::class, 'doctor_option_id')->withTrashed();
    }

    // 定义一个public方法访问图片或文件
    public function getPayImages()
    {
        if (!$this->pay_images) {
            return $this->pay_images;
        }
        $images = [];
        foreach (json_decode($this->pay_images, true) as $item) {
            $images[] = getAliOssUrl($item);
        }
        return $images;
    }
}
